<template>
  <div class="addGoods">
    <el-steps :active="active" finish-status="success">
      <el-step title="步骤 1"></el-step>
      <el-step title="步骤 2"></el-step>
      <el-step title="步骤 3"></el-step>
      <el-step title="步骤 4"></el-step>
      <el-step title="步骤 5"></el-step>
    </el-steps>

    <el-tabs :tab-position="tabPosition" v-model="activeName" @tab-click="handleClick" class="mt-20">
      <el-tab-pane label="基本信息" name="first">基本信息</el-tab-pane>
      <el-tab-pane label="商品参数" name="second">商品参数</el-tab-pane>
      <el-tab-pane label="商品属性" name="third">商品属性</el-tab-pane>
      <el-tab-pane label="商品图片" name="fourth">
        <el-upload
          class="upload-demo"
          action="http://localhost:8888/api/private/v1/upload"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :on-success="handleSubmit"
          :headers="setHeader()"
          list-type="picture">
          <el-button size="small" type="primary">点击上传</el-button>
          <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
        </el-upload>
      </el-tab-pane>
      <el-tab-pane label="商品内容" name="fifth">商品内容</el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
export default {
  data () {
    return {
      active: 0,
      activeName: 'first',
      tabPosition:'left',
    }
  },
  methods: {
    handleClick(tab, event) {
      // console.log(tab ,event)
      switch (tab.name) {
        case 'first':
          this.active = 1
          break
        case 'second':
          this.active = 2
          break
        case 'third':
          this.active = 3
          break
        case 'fourth':
          this.active = 4
          break
        case 'fifth':
          this.active = 5
          break

        default:
          break;
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleSubmit(response, file, fileList) {
      if (response.meta.status == 200) {
        this.$message({
          type: 'success',
          message: '图片上传成功'
        })
      }
    },
    setHeader() {
      let token = localStorage.getItem('mytoken')
      return {'Authorization': token}
    }
  }
}
</script>
<style lang="scss" scoped>
.addGoods {
  .mt-20 {
    margin: 20px;
  }
}
</style>
